package net.vonkannen.callduration;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class CustomToast {
	Toast toast;
	
	CustomToast(Context context, String string, int borderRadius, int borderThickness, int borderColor, int bgColor, int fontColor, boolean showIcon) {
        /* Create toast */
		GradientDrawable shape_toast = new GradientDrawable();
		LinearLayout lay_toast = new LinearLayout(context);
		ImageView img_toast = new ImageView(context);
		TextView tv_toast = new TextView(context);
		toast = new Toast(context);
        
        shape_toast.setCornerRadius(borderRadius);
        shape_toast.setStroke(borderThickness, borderColor);
        shape_toast.setColor(bgColor);
        
        lay_toast.setBackgroundDrawable(shape_toast);
        lay_toast.setPadding(20, 20, 20, 20);
        
        if(showIcon) {
	        img_toast.setImageResource(R.drawable.icon);
	        img_toast.setPadding(0, 0, 5, 0);
	        lay_toast.addView(img_toast);
        }
        
        tv_toast.setTextColor(fontColor);
        tv_toast.setGravity(Gravity.CENTER_VERTICAL);
        tv_toast.setHeight(72);
        tv_toast.setText(string);
        
        lay_toast.addView(tv_toast);
        
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.setView(lay_toast);
	}
	
	public void show() {
		toast.show();
	}
}
